Deal or No Deal

Greg Buchholz on 2006-03-10T17:14:08

Here's a small CGI program to calculate the expected value of the remaining cases on the TV show Deal or No Deal (Oh, and the all important screen shot).

#!/usr/bin/perl
use CGI; 

$q = new CGI;
print $q->header;
print $q->start_html(-title=>'Deal or No Deal',-BGCOLOR=>'white'),
      $q->h1('--Deal or No Deal--'),
      $q->startform();
     
@left =   qw/ 0.01       1       5      10      20     50  
                75     100     200     300     400     500     750  /;
           
@right=   qw/1,000   5,000  10,000  25,000  50,000  75,000
           100,000 200,000 300,000 400,000 500,000 750,000 1,000,000/; 

my $i = 0;
print "\n";
for (@left)
{
    print $q->Tr($q->th([
                         $q->checkbox(-name=>"cl$i",
                                  	  -checked=>'checked',
                    		          -value=>'YES',
                    		          -label=>'').
                        $q->textfield(-name=>"l$i",
                                      -default=>$left[$i],
                                      -size=>9, 
                                      -override=>0),
                                      
                        $q->textfield(-name=>"r$i",
                                      -default=>$right[$i],
                                      -size=>9, 
                                      -override=>0).
                         $q->checkbox(-name=>"cr$i",
                                  	  -checked=>'checked',
                    		          -value=>'YES',
                    		          -label=>'')
                                      ])), "\n";
    $i++;    
}
print "
"; print $q->submit(-name=>'Calculate'), $q->endform() ; if (@all = $q->param()) { my $acc = 0; my $count = 0; for (@all) { if(/c((?:l|r)\d+)/) { my $val = $q->param($1); $val =~ s/[^.0-9]//g; $count++; $sum += $val; } } print "

Expected Value: ".'$'; printf "%.2f


", $sum/$count; } print $q->end_html;


Too simple perhaps?

Alias on 2006-03-11T04:52:19

I don't know a lot about statistics, but I know that it is rarely as simple as we expect.

Fortunately, computers are fast.

You might want to take the simple approach of just running every possible game recursively, and then averaging all the results from there.

Re:Too simple perhaps?

Greg Buchholz on 2006-03-12T05:06:15

Is there a specific critique you have in mind? Did I screw up the calculation for expected value somehow?